#!/bin/bash
#count httpd 8080
#统计每个状态的个数
declare -A webstart
web=`ss -tnlp|grep 8080|awk '{print $1}'`
for i in $web
do
    let webstart[$i]++
done
#通过遍历数组里的索引和元素打印出来
for j in ${!webstart[@]}
do
    echo $j:${webstart[$j]}
done
if [ -z "$web" ]
then
    echo "LISTEN:0"
#启动httpd服务
    read -p "Do you want to htttpd server(yes/no)" switch
    case $switch in
    Y|YES|y|yes)
        systemctl start httpd&>/dev/null
        echo "httpd server successful"
    ;;
    N|NO|n|no)
        echo "two second exit"
        sleep 2 && exit
    ;;
    esac
fi